package com.ldx.blog.common.utils;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

public class SecurityUtils {
    public static String encrypt(String password){
        String salt = UUID.randomUUID().toString().replace("-","");
        String finalPassword = DigestUtils.md5DigestAsHex((password+salt).getBytes(StandardCharsets.UTF_8));
        return salt+finalPassword;

    }
    public static boolean verify(String inputPassword,String sql){
        String salt = sql.substring(0,32);
        String finalPassword = DigestUtils.md5DigestAsHex((inputPassword+salt).getBytes(StandardCharsets.UTF_8));
        if (sql.equals(salt+finalPassword)){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        String password = "123456";
        System.out.println(encrypt(password));
        String sql = "b6203864f0d243b69cbe7dfbaf608f85f2a3ad4980f83daf6e9b991fe0a2d783";
        System.out.println(verify("123456", sql));

    }
}
